<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>音乐题生成器</title>
    <style>
        #count{
            margin-top: 1rem;
        }
    </style>
</head>
<body>
    <div class="layui-card">
        <div class="layui-card-header">
            音乐题生成器
        </div>
        <div class="layui-card-body">
            <div class="layui layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">间隔</label>
                    <div class="layui-input-block">
                        <input type="number" id="gap" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">音符序列</label>
                    <div class="layui-input-block">
                        <textarea id="noteList" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">生成配置</label>
                    <div class="layui-input-block">
                        <button class="layui-btn" onclick="generateString()">
                            生成
                        </button>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">生成结果</label>
                    <div class="layui-input-block">
                        <textarea id="result" rows="12" class="layui-textarea"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
function generateString(){
    const gap = $('#gap').val();
    const noteData = $('#noteList').val().split('');
    let noteList = []
    for(let i = 0; i < noteData.length; i++) {
        if(noteData[i] == 0) continue;
        let data = {
            component: 'musicNote',
            pos: i * gap,
            x: parseInt(noteData[i]),
        }
        noteList.push(data);
    }
    console.log(noteList);
    let result = JSON.stringify(noteList);
    $('#result').val(result);
}
</script>
</html>